home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mc51bugs.zip / Q30453 < prev    next >
Text File  |  1988-07-21  |  3KB  |  103 lines

  1. Q30453 Incorrect Code Generation for Switch Statement
  2. C Compiler
  3. 5.10
  4. MS-DOS
  5.  
  6. Summary:
  7.    The compiler generates incorrect code for a switch statement under
  8. specific circumstances.
  9.    The program has several case statements and the compiler detects
  10. common code in two of the cases. It generates an unconditional jump to
  11. a label that seems to be off by one instruction i.e., a certain path
  12. is taken in cases where it should not be taken.
  13.  
  14. More Information:
  15.    The code generated for case 4: includes an unconditional jump to a
  16. CALL to the function err_alarm(2). The compiler sees that the
  17. CALL to err_alarm(2) is the same in case 2: and jumps to that
  18. code. However, the condition of the loop is never evaluated.
  19.    Work around the problem by changing the if statement in case 4: as
  20. follows:
  21.  
  22.               case 4:                 /* Legal file name chars */
  23.                 if (isgraph(char_in)
  24.  
  25. The following is a code example:
  26.  
  27. #include <ctype.h>
  28.  
  29. int     context;
  30. int   strgin(inp_string,len,type)
  31. char   *inp_string;          /* 1=string 2=hex 3=dec 4=file name */
  32. int   len, type;                 /*    || 00=screen 10=window  */
  33. {
  34.    int   char_in;
  35.    int   i = 0;
  36.    int   *prow, *pcol;
  37.    int   row,col;
  38.  
  39.    prow = &row;
  40.    pcol = &col;
  41.  
  42.    i = strlen(inp_string);
  43.    do
  44.       {
  45.       if (!chin(&char_in))
  46.          continue;
  47.  
  48.                if (i < len)
  49.                   {
  50.                   switch (type & 0x0f)
  51.                      {
  52.                      case 1:                    /* ASCII string */
  53.                         if (0 == isprint(char_in))
  54.                            continue;
  55.                         break;
  56.                      case 2:                    /* Hexidecimal only */
  57.                         if (0 == isxdigit(char_in) && 0 == isspace(char_in))
  58.                            {
  59.                            err_alarm(2);
  60.                            continue;
  61.                            }
  62.                         break;
  63.                      case 3:                    /* Decimal only */
  64.                         if (0 == isdigit(char_in))
  65.                            {
  66.                            err_alarm(3);
  67.                            continue;
  68.                            }
  69.                         break;
  70.                      case 4:             /* Legal filename chars */
  71.                         if (0 == isgraph(char_in))
  72.                            {
  73.                            err_alarm(2);
  74.                            continue;
  75.                            }
  76.                         break;
  77.                      default:
  78.                         continue;
  79.                         break;
  80.                      }
  81.                   if (type & 0x10)
  82.                      wnwrtty((char)char_in, -1,-1);
  83.                   else
  84.                      scttywrt((char)char_in,-1);
  85.                   inp_string[i++] = (char)char_in;
  86.                   inp_string[i] = '\0';
  87.                   }
  88.                else
  89.                   {
  90.                   err_alarm(2);
  91.                   context = 44;
  92.                   disp_help_line(94);
  93.                   }
  94.             }
  95.    while (char_in != '\r');
  96. }
  97.  
  98.  
  99.  
  100.  
  101. Keywords:  buglist5.10
  102. Updated  88/07/21 03:19
  103.